import { defHttp } from '@/utils/http/axios';

enum Api {
  ScriptsPageAPI = '/scripts/page',
  addscript = '/scripts/add',
  OtherVersionsAPI = '/scripts/versions',
  setselectVersionAPI = '/scripts/selectVersion',
  addscriptTextAPI = '/scripts/addText',
  updateRemarkAPI = '/scripts/updateRemark',
  deleteScriptAPI = '/scripts/removes',
}

//脚本
export function getScriptsPageAPI(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.ScriptsPageAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;
      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '虚拟机');
    });
}
export function addscriptAPI(params) {
  return defHttp
    .post(
      {
        url: Api.addscript,
        data: params,
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function addscriptTextAPI(params) {
  return defHttp
    .post(
      {
        url: Api.addscriptTextAPI,
        data: params,
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

export function getOtherVersionsAPI(params) {
  return defHttp
    .get(
      {
        url: Api.OtherVersionsAPI + '?name=' + params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function getCmdAPI(params) {
  return defHttp
    .get(
      {
        url: '/fb/cmd/list',
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function setselectVersionAPI(params) {
  return defHttp
    .post(
      {
        url: `${Api.setselectVersionAPI}?name=${params.name}&version=${params.version}`,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
//修改备注接口
export function updateRemarkAPI(params) {
  return defHttp
    .post(
      {
        url: `${Api.updateRemarkAPI}?id=${params.id}&remark=${params.remark}`,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function addScriptAPI(params) {
  return defHttp
    .post(
      {
        url: `/fb/device/add/script`,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
//删除脚本接口

export function deleteScriptAPI(params) {
  return defHttp
    .get(
      {
        url: `${Api.deleteScriptAPI}?name=${params.name}`,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function deletecount(params) {
  return defHttp
    .get(
      {
        url: `/sys/analysis/collection/device/count?mac=` + params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
export function deleteDeviceScriptAPI(params) {
  return defHttp
    .get(
      {
        url: `/fb/device/delete/script?id=${params}`,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
